<template>
	<view class="register-container">
		<form class="form">
			<view class="title-desc">
				<view class="title">手机号登录</view>
				<view class="desc">未注册的手机号登录后自动注册</view>
			</view>
			<view class="item">
				<input type="text" v-model="username" placeholder="请输入用户名"
					placeholder-style="color:#999;font-size:14px;" />
			</view>
			<view class="item">
				<input type="number" v-model="mobile" placeholder="请输入手机号码"
					placeholder-style="color:#999;font-size:14px;" />
			</view>
			<view class="item flex-sb">
				<input type="number" v-model="smsCode" placeholder="请输入手机验证码"
					placeholder-style="color:#999;font-size:14px;" />
				<view class="code">获取验证码</view>
			</view>
			<button class="submit" @click="toLogin">登录</button>
			<view class="login">
				<!-- <button class="btn-normal" open-type="getPhoneNumber"
					@getphonenumber="handelMpWeixinMobileLogin($event)">
					<unt-icon name="icon-weixin" size="16" color="#28C445"></unt-icon><text class="text">手机号一键登录</text>
				</button> -->
			</view>
		</form>
	</view>
</template>

<script>
	import store from '@/store'
	const SUBMIT_LOGIN = 20;
	export default {
		data() {
			return {
				username: "",
				// 手机号
				mobile: '',
				// 短信验证码
				smsCode: ''
			}
		},
		methods: {
			// 表单验证
			formValidation(scene) {
				// 验证提交登录
				if (scene === SUBMIT_LOGIN) {
					if (!this.validteMobile(this.mobile) || !this.validteSmsCode(this.smsCode)) {
						return false
					}
				}
				return true
			},
			validteMobile(str) {
				if (uni.$unt.isEmptyStr(str)) {
					this.$toast('请先输入手机号')
					return false
				}
				if (!uni.$unt.isMobile(str)) {
					this.$toast('请输入正确格式的手机号')
					return false
				}
				return true
			},
			// 验证短信验证码
			validteSmsCode(str) {
				if (uni.$unt.isEmpty(str)) {
					this.$toast('请先输入短信验证码')
					return false
				}
				return true
			},
			toLogin() {
				if (this.formValidation(SUBMIT_LOGIN)) {
					this.submitLogin()
				}
			},
			submitLogin() {
				const app = this
				store.dispatch('Login', {
						smsCode: app.smsCode,
						mobile: app.mobile,
					})
					.then(result => {
						console.log(result)
					})
					.catch(err => {
						console.log(err)
					})
					.finally(() => app.isLoading = false)
			},
			// 获取用户手机号
			handelMpWeixinMobileLogin({
				detail
			}) {
				console.log(detail)
			}
		}
	}
</script>

<style lang="scss">
	.register-container {
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 80rpx 40rpx 0rpx 40rpx;

		.form {
			width: 100%;
			margin-top: 40rpx;

			.title-desc {
				margin-bottom: 100rpx;

				.title {
					font-size: 50rpx;
					font-weight: bold;
					letter-spacing: 7rpx;
				}

				.desc {
					font-size: 28rpx;
					color: #999;
					margin-top: 10px;
				}
			}

			.item {
				padding: 30rpx 0rpx;
				border-bottom: 2rpx solid #F9F9FB;

				input {
					padding-left: 10rpx;
				}
			}

			.code {
				font-size: 28rpx;
				color: #0eb83a;
			}

			.submit {
				margin-top: 100rpx;
				width: 90%;
				color: #fff;
				background-color: $me-btn-color;
				text-align: center;
				border-radius: 400rpx;
				margin-left: 5%;
				font-size: 32rpx;
				letter-spacing: 8rpx;
				border: none;
				outline: none;
			}

			.submit::after {
				border: none;
				background: none !important;
			}

			.submit[disabled] {
				background-color: $me-btn-color-disa;
				border: none;
				outline: none;
			}

			.login {
				text-align: center;
				margin-top: 50rpx;

				.text {
					margin-left: 10rpx;
					font-size: 28rpx;
				}
			}
		}
	}
</style>
